package cn.fighter3.service.node;

import cn.fighter3.entity.node.Mscbook;
import cn.fighter3.entity.node.Mulbook;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

import java.util.List;

public interface MulbookDao extends Neo4jRepository<Mulbook,String> {
    //查询--按名字
    List<Mulbook> findByTitle(String title);
    //查询--按id
    Mulbook findByBookId(String id);
    //模糊查询
//    @Query("match(n:Mulbook) where n.title =~'.*{name}.*' return n")
//    Mulbook find(@Param(value="name") String name);
    List<Mulbook> findByTitleLike(String name);
    //删除
    void deleteByBookId(String id);
    @Query("match (n:Mulbook) where n.title=$title detach delete n")
    void deleteByTitle(String title);

    //更新修改
    @Query("match (n:Mulbook) where n.bookId = $id set n.title = $title, n.M_PUBLISHER = $publish, n.M_CALL_NO = $call, n.m_PUB_YEAR = $year return n")
    Mulbook updateByNode(String id,String title,String publish,String call,String year);

   // @Query("match (n:Mulbook) return n limit 25")
    @Query("match (a:Mulbook)-[r]->(b) return a,count(r) order by count(r) DESC limit 20")
    List<Mulbook> all4();

    //查询关系数量
    //MATCH (n:Mulbook {bookId:$id})-[]-() RETURN count(*)
    //profile match (n:Mulbook) where n.bookId = $id return size((n)-[]-())
    @Query("MATCH (n:Mulbook {bookId:$id})-[]-() RETURN count(*)")
    Integer countmul(String id);
}
